<?php
/**	
*	FILENAME: 		/libraries/admin_privileges.php
*	DESCRIPTION:	This library contains and returns information related to the administrative rights of certain user accounts.
*	AUTHOR:			Casey Burkhardt
*	VERSION:		1.0.0
*	LAST MODIFIED:	12/30/2009
**/

require_once($_SERVER["DOCUMENT_ROOT"] . "/libraries/database.php");

/**	
*	DESCRIPTION:	Returns a string containing all of the email addresses which receive notifications in the format:
*					user1@domain.com, user2@domain.com, user3@domain.com
**/
function getNotificationAddresses($type = "error_notifications") {
	connectToDatabase();
	$sql = "SELECT *
			FROM `admin_privileges`
			WHERE `" . $type . "` = '1';";
	$result = mysql_query($sql) or die(mysql_error());
	if (mysql_num_rows($result) > 0) {
		$first = TRUE;
		while ($row = mysql_fetch_assoc($result)) {
			if ($first)	{
				$addresses = $row["notification_address"];
				$first = FALSE;
			} else {
				$addresses .= ", " . $row["notification_address"];
			}
		}
		return $addresses;
	} else {
		return "";
	}	
}

/**	
*	DESCRIPTION:	Returns true if the provided user ID has access to the MyNova Mobile Administrative Panel or false otherwise
**/
function hasAdminPanelAccess($userID) {
	connectToDatabase();
	$sql = "SELECT *
			FROM `admin_privileges`
			WHERE `uid` = '" . $userID . "';";
	$result = mysql_query($sql) or die(mysql_error());
	if (mysql_num_rows($result) > 0) {
		$row = mysql_fetch_assoc($result);
		if ($row["admin_panel"] == 1) {
			return TRUE;
		} else {
			return FALSE;
		}
	} else {
		return FALSE;
	}
}

/**	
*	DESCRIPTION:	Returns true if the provided user ID has access to the MyNova Mobile usage statistics or false otherwise
**/
function hasUsageStatsAccess($userID) {
	connectToDatabase();
	$sql = "SELECT *
			FROM `admin_privileges`
			WHERE `uid` = '" . $userID . "';";
	$result = mysql_query($sql) or die(mysql_error());
	if (mysql_num_rows($result) > 0) {
		$row = mysql_fetch_assoc($result);
		if ($row["usage_stats"] == 1) {
			return TRUE;
		} else {
			return FALSE;
		}
	} else {
		return FALSE;
	}
}
?>